package be.dch.gui.components;

import java.awt.Graphics;
import java.awt.Image;

import javax.swing.JPanel;

import be.dch.util.ImageUtils;

public class JImagePanel extends JPanel {

    private static final long serialVersionUID = -6869325900938813712L;
    private transient Image image;

    public JImagePanel() {
	super();
	this.noImage();
    }

    public JImagePanel(final Image image) {
	super();
	this.setImage(image);
    }

    @Override
    public final void paintComponent(final Graphics grap) {
	grap.drawImage(this.image, 0, 0, this);
	this.repaint();
    }

    public final void setImage(final Image image) {
	this.setSize(image.getWidth(this), image.getHeight(this));
	this.setPreferredSize(this.getSize());
	this.image = image;
    }

    public final void noImage() {
	this.setImage(ImageUtils.toBufferedImage(this.getClass().getResource("/images/typeditor-questionmark-icon.jpg")));

    }

}
